//
//  CodeExchangeViewController.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/3/30.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "CodeExchangeViewController.h"

@interface CodeExchangeViewController ()<DYQBannerScrollViewDelegate>
/*****/
@property (strong,nonatomic) DYQBannerScrollView *bannerScrollView;//广告栏

@property (nonatomic,strong)  NSMutableArray  *imageArray;
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroView;

@property (strong, nonatomic) IBOutlet UIView *imageView;

@property (strong, nonatomic) IBOutlet UILabel *goodsTitle;
@property (strong, nonatomic) IBOutlet UILabel *brandsName;
@property (strong, nonatomic) IBOutlet UILabel *goodsName;
@property (strong, nonatomic) IBOutlet UILabel *madePlace;
@property (strong, nonatomic) IBOutlet UILabel *madeForWhat;//材料
@property (strong, nonatomic) IBOutlet UILabel *washIntroduce;//洗涤说明
@property (strong, nonatomic) IBOutlet UILabel *remark;
@property (strong, nonatomic) IBOutlet UILabel *goodsNumber;
@property (strong, nonatomic) IBOutlet UILabel *goodsNeedCode;//需要积分及原价

@end

@implementation CodeExchangeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.imageArray = [NSMutableArray array];

    // Do any additional setup after loading the view.
    [self initViewLayout];
    [self getAdvertiseBanner];
    [self getGoodsInfo];
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.scroView];
    [self adaptiveViewLayout:self.imageView];
    [self adaptiveViewLayout:self.navView];
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 700), YES);
    
    //广告栏
    
    self.bannerScrollView = [[DYQBannerScrollView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 320, 320), NO)];
    self.bannerScrollView.backgroundColor = [UIColor clearColor];
    self.bannerScrollView.pageControlPosition = PageControlPositionCenter;
    self.bannerScrollView.noDataPlaceholderImage = [UIImage imageNamed:@"cover_cy"];
    self.bannerScrollView.timeInterval = 3;
    self.bannerScrollView.pageControllerTintColor = [UIColor whiteColor];
    self.bannerScrollView.pageControllerCurrentColor = [UIColor orangeColor];
    
//    [self.scroView addSubview:_bannerScrollView];
    
    
}
- (IBAction)back:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}
#pragma mark == 收藏
- (IBAction)collect:(id)sender {
}

#pragma mark == 分享
- (IBAction)shareHandel:(id)sender {
    
}


#pragma mark == 商品详情
- (void)getGoodsInfo{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:_goodsId forKey:@"goodsId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_ADBanner withHttpType:@"POST" withTag:SX_kADBannerTag];
}

#pragma mark  获取首页广告BANNER--=========================================
-(void)getAdvertiseBanner{
    
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:@"queryMallADDData" forKey:@"method"];
    [dic setObject:@"1" forKey:@"position"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_queryContext withHttpType:@"POST" withTag:SX_SX_queryContext];
}


#pragma mark----DYQBannerScrollViewDelegate

-(void)bannerScrollView:(DYQBannerScrollView *)bannerScrollView didSelectItemAtIndex:(NSInteger)index
{
    //    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"PersonCenterStoryboard" bundle:nil];
    //    WebDetailInfoViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"WebDetailInfo"];
    //    page.objectId = _bannerArray[index][@"appAdertUrl"];
    //    page.titleStr = @"详情";
    //    page.meType = @"4";
    //    [self.navigationController  pushViewController:page animated:YES];
}



#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    
    
    if (tag==SX_kADBannerTag) {
        
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            [self.imageArray removeAllObjects];
            //            self.imageArray = database[@"result"];
            for (NSDictionary *data in database[@"result"]) {
                
                NSString * picture = [Common stringFromData:data[@"appAdertImagUri"]];
                [self.imageArray addObject:picture];
            }
            _bannerScrollView.imageUrls = _imageArray;
            _bannerScrollView.delegate = self;
            
            
        }
        
    }else if (tag == SX_SX_queryContext){
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            
        
        }
    
    }
}



-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    //
    [self dismissWaitDialog];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
